package Algorithm;

import java.util.Arrays;

public class test6 {
    // 给定一个数s,判断数组中是否存在两数之和等于s
    // 算法原理: 双指针
    public static void main(String[] args) {
        int[] price = {8, 21, 27, 34, 52, 66};
        int[] nums = new int[2];
        int left = 0, right = price.length - 1, target = 61;
        while (left < right) {
            if (price[left] + price[right] > target) {
                right--;
            }
            if (price[left] + price[right] < target) {
                left++;
            }
            if (price[left] + price[right] == target) {
                nums[0] = price[left];
                nums[1] = price[right];
                break;
            }
        }
        System.out.println(Arrays.toString(nums));
    }
}
